﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for connection
/// </summary>
public class connection
{
    public static String ConnectionString = "Data Source=localhost;Initial Catalog=chodientu;Integrated Security=True";
    public SqlConnection conn { get; set; }
	public connection()
	{
        conn = new SqlConnection(this.get_connectionstring());
	}
    public string get_connectionstring() { return ConnectionString; }
    public void Open()
    {
        
        conn.Open();
    }
    public void Close()
    {
        conn.Close();
    }
    public DataView Ds_table(DataSet ds, string sql,string table_name)
    {
        SqlDataAdapter adapter = new SqlDataAdapter(sql,conn);
        adapter.Fill(ds, table_name);
        return ds.Tables[table_name].DefaultView;
    }
    public DataTable return_table(DataSet ds, string sql, string table_name)
    {
        SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
        adapter.Fill(ds, table_name);
        return ds.Tables[table_name];
    }
	public DataSet return_dataset(DataSet ds, string sql, string table_name)
    {
        SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
        adapter.Fill(ds, table_name);
        return ds;
    }
    public void Execute_noquery(string sql)
    {
        SqlCommand command = new SqlCommand(sql, conn);
        command.ExecuteNonQuery();
    }
    public string Execute_reader(string sql,string column)
    {
        
        SqlCommand command = new SqlCommand(sql, conn);
        SqlDataReader reader = command.ExecuteReader();
        reader.Read();
        string mashop = reader[column].ToString();
        reader.Close();
        return mashop;
    }
   
}